package com.lishe.lishe.lishe.module.mall.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.base.BaseActivity;
import com.lishe.lishe.lishe.module.mall.adapter.CheckGoodsImgAdapter;

import java.util.ArrayList;

/**
 * Created by Bin on 2018/5/7.
 * 查看图片
 */

public class CheckGoodsImgActivity extends BaseActivity {

    public static final String IMG_LIST = "IMG_LIST";
    public static final String CURRENT_INDEX = "IMG_CURRENT_INDEX";

    private TextView mTvIndex;
    private ViewPager mViewPager;
    private int mCurrentIndex;
    private ArrayList<String> mImages;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_checkgoodsimg);
        
        // 需要展示的img数组
        mImages = getIntent().getStringArrayListExtra(IMG_LIST);
        // 当前展示图片的下标
        mCurrentIndex = getIntent().getIntExtra(CURRENT_INDEX,0);
        initView();
    }

    private void initView() {
        mViewPager = findViewById(R.id.view_pager);
        mViewPager.setAdapter(new CheckGoodsImgAdapter(this,mImages, new CheckGoodsImgAdapter.ItemClicker() {
            @Override
            public void onItemClick() {
                finish();
            }
        }));
        mViewPager.setCurrentItem(mCurrentIndex);
        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mCurrentIndex = position;
                mTvIndex.setText(mCurrentIndex + 1 + "/" + mImages.size());
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        mTvIndex = findViewById(R.id.index);
        mTvIndex.setText(mCurrentIndex + 1 + "/" + mImages.size());
    }

}